package com.neuedu.his.dao;


import com.neuedu.his.common.utils.DBUtils;
import com.neuedu.his.entity.RegistLevel;

import java.util.List;
import java.util.Map;

public class RegistLevelDao {

    /**
    * 查询集合
    */
    public List<RegistLevel> selectList(String where , Object ... params){
        String sql =" select * from regist_level ";
        if(where != null && !"".equals(where)){
            sql += where;
        }
        List<RegistLevel> registLevels = DBUtils.selectList(RegistLevel.class, sql, params);

        return registLevels;
     }

    /**
    * 分页查询
    * @param where
    * @param pageNo
    * @param size
    * @param params
    * @return
    */
    public List<RegistLevel> selectPage(String where , int pageNo,int size ,Object ... params){
        String sql =" select * from regist_level ";
        if(where != null && !"".equals(where)){
        sql += where;
        }

        sql += " limit "+(pageNo-1)*size+"   ,"+size;

        System.out.println("sql = " + sql);
        List<RegistLevel> registLevels = DBUtils.selectList(RegistLevel.class, sql, params);

        return registLevels;
    }


    /**
    * 查询单条结果
    */
    public RegistLevel selectOne(String where ,Object ... params){
        String sql =" select * from regist_level ";
        if(where != null && !"".equals(where)){
            sql += where;
        }
        return DBUtils.selectOne(RegistLevel.class, sql, params);
    }


    /**
     * 查询总条数
     */
    public long selectCount(String where ,Object ... params){
        String sql =" select * from regist_level ";
        if(where != null && !"".equals(where)){
            sql += where;
        }

        sql = "select count(1) count from ("+ sql  +") tab   ";
        Map map = DBUtils.selectMap( sql , params);
        long count = (long) map.get("count");
        return count;
    }




    /**
    * 根据数据进行插入
    * @param registLevel
    * @return
    */
    public int insert(RegistLevel registLevel){
        String sql = "insert into regist_level(       caption   ,       fee   ) values(   ?   ,     ?    )";
        return DBUtils.update( sql,    registLevel.getCaption()    ,     registLevel.getFee() );
    }


    /**
    * 根据主键更新一条
    * @param registLevel
    * @return
    */
    public int updateById(RegistLevel registLevel){
        String sql = " update regist_level set     caption = ?   ,       fee = ?   where  regist_level = ?  ";

        return DBUtils.update( sql,
                    registLevel.getCaption()  ,
                    registLevel.getFee()  ,
                    registLevel.getRegistLevel() );
    }



    /**
    * 根据主键更新一条
    * @param id
    * @return
    */
    public int deleteById(Integer id){
        String sql = " delete from regist_level  where regist_level = ?";
        return DBUtils.update( sql, id);

    }


}